package com.zwk.nginxmanage.advice;

import com.zwk.nginxmanage.common.R;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;

@Component
@Aspect
public class NginxAdvice {

    @Autowired
    private HttpSession session;

    @Around("within(com.zwk.nginxmanage.controller.ViewController)")
    public Object auth(ProceedingJoinPoint pdj) throws Throwable {
        Object user = session.getAttribute("user");
        if (user==null){
            return R.error(302,"请先登录").put("loginStatus",false);
        }
        return pdj.proceed();
    }
}
